import { _decorator, Component, director, instantiate, Node, Prefab, resources } from 'cc';
import { userinfo } from '../../UserInfo';
import { GameEvent } from '../../GameEvent';
import { fishComp } from '../fish/fishComp';
import protocol from 'db://assets/proto/protoExt';

const { ccclass, property } = _decorator;
@ccclass('bottomui')
export class bottomui extends Component {
    @property(Node)
    content: Node = null!;

    start() {
        director.on(GameEvent.addFish, (fish: protocol.new_world.shared.v1.ImmortalDetail) => {
            let fishNode = instantiate(resources.get("prefab/fish", Prefab)!)
            this.content.addChild(fishNode)
            fishNode.getComponent(fishComp)!.setFish(fish.fish!)
        })
        this.updateUI()
    }
    updateUI() {
        let fishs = userinfo.getFishs()
        for (let i = 0; i < fishs.length; i++) {
            let fishNode = instantiate(resources.get("prefab/fish", Prefab)!)
            this.content.addChild(fishNode)
            fishNode.getComponent(fishComp)!.setFish(fishs[i].fish!)
        }
    }

    update(deltaTime: number) {

    }
}


